package com.hxzy.system.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hxzy.common.core.domain.entity.CmsContent;
import com.hxzy.common.enums.AckCode;
import com.hxzy.common.exception.TzxmException;
import com.hxzy.system.domain.dto.CmsContentDTO;
import com.hxzy.system.mapper.CmsContentMapper;
import com.hxzy.system.service.CmsContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class CmsContentServiceImpl extends ServiceImpl<CmsContentMapper, CmsContent> implements CmsContentService {

    @Autowired
    private CmsContentMapper cmsContentMapper;

    @Override
    public IPage<CmsContent> search(CmsContentDTO cmsContentDTO) {
        IPage<CmsContent> page= PageDTO.of(cmsContentDTO.getPageNum(),cmsContentDTO.getPageSize());
        return this.baseMapper.search(page,cmsContentDTO);
    }

    @Override
    public boolean edit(CmsContent cmsContent) {
        CmsContent byId = this.findById(cmsContent.getId());
        if (Objects.isNull(byId)){
            throw  new TzxmException(AckCode.NOT_FOUND_DATA);
        }
        int b = this.cmsContentMapper.updateInid(cmsContent);
        return b==0? false:true;
    }

    @Override
    public CmsContent findById(Long id) {
      CmsContent cmsContent=this.baseMapper.findById(id);
      return cmsContent;
    }

    @Override
    public boolean seave(CmsContent cmsContent) {
        int b=this.cmsContentMapper.insertinto(cmsContent);
        return b!=0?true:false;
    }
}
